#!/bin/bash

set -e

SCRIPTS=$(dirname "$(realpath "$0")")
#shellcheck disable=SC1090
source "${SCRIPTS}/functions"

check_command_exists python git awk sed pip npm xargs grep

check_virtual_env

status "- Installing needed python modules (silent)"
grep -v django-cms docs/requirements.txt | grep -v '#' | xargs pip install --quiet django-admin &>/dev/null

check_command_exists django-admin

if [ ! -d cms ] ; then
    error "Please only run this command within the django CMS root folder"
    exit 1
fi

nvm_ver="$(cat .nvmrc)"

cd cms
status "- Installing node/npm"

load_nvm

nvm install "${nvm_ver}"
nvm use "${nvm_ver}"

status "- Installing required node packages (silent)"
npm install &>/dev/null

if ! command -v gulp; then
    npm install gulp@4.0.2 --loglevel warn
    check_command_exists gulp
fi

status "- Installing transifex cli and gettext"
( cd "$SCRIPTS" && curl -o- https://raw.githubusercontent.com/transifex/cli/master/install.sh | bash &>/dev/null )
sudo apt-get -qq install gettext &>/dev/null

